﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;

public partial class Order_OrderClear : System.Web.UI.Page
{

    private DataTable TempDataTable
    {
        get
        {
            DataTable tempTable = new BLL.RETURNDOCPAYDETAIL().CreateTempDataTable();
            //DataTable tempTable = null;
            if (ViewState["TempDataTable"] != null)
            {
                tempTable = (DataTable)ViewState["TempDataTable"];
            }
            return tempTable;
        }
        set
        {
            ViewState["TempDataTable"] = value;
        }
    }

    private string Code
    {
        get
        {
            return Request.QueryString["code"] != null ? Request.QueryString["code"].ToString() : "";
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetOrderInfo();
            BindDataListCoupon();
        }
    }

    private void GetOrderInfo()
    {
        string orderid = Request.QueryString["code"].ToString().Trim();
        Model.ORDERDOC od = new BLL.ORDERDOC().GetModel(orderid);

        if (od.ORDER_LOCKER != Share.UserValue(0) && od.ORDER_LOCKER != "000" && od.ORDER_LOCKER != "")
        { Response.Redirect(BLL.Common.GetWebPath() + "/Error.aspx"); }
        lblorderid.Text = od.ORDER_ID;
        lblspje.Text = Decimal.Round(od.ORDER_AMT, 2).ToString();
        lblsl.Text = Decimal.Round(od.ORDER_QTY, 0).ToString();
        lblorderrq.Text = od.ORDER_CREATEDATE.ToString();
        lblorderje.Text = Decimal.Round(od.ORDER_AAMT, 2).ToString();
        lblksrq.Text = od.ORDER_CHECKDATE == DateTime.MinValue ? "" : od.ORDER_CHECKDATE.ToString();
        lblfhrq.Text = od.ORDER_SENDDATE == DateTime.MinValue ? "" : od.ORDER_SENDDATE.ToString();
        lbldeleterq.Text = od.ORDER_DELETEDATE == DateTime.MinValue ? "" : od.ORDER_DELETEDATE.ToString();

        HyperLink1.Text = od.ORDER_AID;
        HyperLink1.NavigateUrl = "OrderDetail.aspx?code=" + od.ORDER_AID.Trim();

        lblzk.Text = od.ORDER_DISC.ToString();

        lblcsrq.Text = od.ORDER_ACHECKDATE == DateTime.MinValue ? "" : od.ORDER_ACHECKDATE.ToString();
        lblclockrq.Text = od.ORDER_LOCKDATE == DateTime.MinValue ? "" : od.ORDER_LOCKDATE.ToString();
        ckbcs.Checked = od.ORDER_ACHECK == 0 ? false : true;
        ckbfh.Checked = od.ORDER_SEND == 0 ? false : true;
        ckbfp.Checked = od.ORDER_NINV == 0 ? false : true;
        txtfptt.Text = od.ORDER_INVTITLE;
        if (ckbfp.Checked) { ScriptManager.RegisterStartupScript(this, this.GetType(), "", "fpfunc();", true); }
        ckbks.Checked = od.ORDER_CHECK == 0 ? false : true;
        ckbsd.Checked = od.ORDER_LOCK == 0 ? false : true;
        ckbzf.Checked = od.ORDER_DELETE == 0 ? false : true;
        txtbz.Text = od.ORDER_NOTE;
        txtrlje.Text = Decimal.Round(od.ORDER_OFFERAMT, 2).ToString();
        txtwlfy.Text = Decimal.Round(od.ORDER_TRANCOST, 2).ToString();
        lblgmr.Text = od.ORDER_CUSTOMERCODE;
        Label2.Text = new BLL.V_CUSTOMER().GetModel(od.ORDER_CUSTOMERCODE).GKMC;
        lblgmr.NavigateUrl = "~/CustomerArchives/CustomerArchiveEdit.aspx?code=" + od.ORDER_CUSTOMERCODE;
        
        lblWeight.Text = String.Format("{0:0}", od.ORDER_WEIGHT);
        ckbjs.Checked = od.ORDER_CLEAR == 0 ? false : true;
        lblJSJE.Text = Decimal.Round(od.ORDER_CLEARAMT, 2).ToString();

        List<Model.TRANER> traner = new BLL.TRANER().GetAllList(true);
        ddlwlfs.DataSource = traner;
        ddlwlfs.DataTextField = "TRANER_NAME";
        ddlwlfs.DataValueField = "TRANER_CODE";
        ddlwlfs.DataBind();
        ddlwlfs.SelectedValue = od.ORDER_TRANERCODE;

        ddlfyxz.SelectedValue = od.ORDER_COSTNATURE;
        ddljylx.SelectedValue = od.ORDER_APAY.ToString();

        

        List<Model.ORDERFROM> of = new BLL.ORDERFROM().GetAllList(true);
        ddlddly.DataSource = of;
        ddlddly.DataTextField = "OF_NAME";
        ddlddly.DataValueField = "OF_CODE";
        ddlddly.DataBind();
        ddlddly.SelectedValue = od.ORDER_OFCODE;

        chkAssureDeal.Checked = od.ORDER_SECDEAL == 1 ? true : false;
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            Model.ORDERDOC order = new BLL.ORDERDOC().GetModel(this.Code);
            if (order == null)
            {
                throw new Exception("系统无法获取该订单信息！");
            }
            if (order.ORDER_CLEAR == 1)
            {
                throw new Exception("订单已经结算，不允许操作！");
            }

            FillValueIntoDataTable(this.TempDataTable);

            decimal payAmount = 0.00M;
            decimal couponPayAmount = 0.00M;
            string operatorId = Share.UserValue(0);
            bool result = false; 


            StringBuilder strSqlToUpdateBStyleDB = new StringBuilder();
            StringBuilder strSqlToUpdateErpDB = new StringBuilder();

            int count = 0;
            for (int i = 0; i < this.TempDataTable.Rows.Count; i++)
            {
                strSqlToUpdateBStyleDB.Append("INSERT INTO [PAYDETAIL]([PD_ID],[PD_DETAILID],[PD_PAYTYPE],[PD_PAYAMT],[PD_PAYDATE],");
                strSqlToUpdateBStyleDB.Append("[PD_DEALID],[PD_DEALDATE],[PD_ACCOUNT],[PD_GET],[PD_GETAMT],[PD_GETDATE],[PD_DTCODE]) VALUES('");
                strSqlToUpdateBStyleDB.Append(this.Code);
                strSqlToUpdateBStyleDB.Append("','");
                strSqlToUpdateBStyleDB.Append(i + 1);
                strSqlToUpdateBStyleDB.Append("','");
                strSqlToUpdateBStyleDB.Append(this.TempDataTable.Rows[i]["RDPD_PAYTYPE"].ToString());
                strSqlToUpdateBStyleDB.Append("',");
                strSqlToUpdateBStyleDB.Append(Convert.ToDecimal(this.TempDataTable.Rows[i]["RDPD_PAYAMT"]));
                strSqlToUpdateBStyleDB.Append(",'");
                strSqlToUpdateBStyleDB.Append(this.TempDataTable.Rows[i]["RDPD_PAYDATE"].ToString());
                strSqlToUpdateBStyleDB.Append("','");
                strSqlToUpdateBStyleDB.Append(this.TempDataTable.Rows[i]["RDPD_DEALID"].ToString());
                strSqlToUpdateBStyleDB.Append("','");
                strSqlToUpdateBStyleDB.Append(this.TempDataTable.Rows[i]["RDPD_DEALDATE"].ToString());
                strSqlToUpdateBStyleDB.Append("','");
                strSqlToUpdateBStyleDB.Append(this.TempDataTable.Rows[i]["RDPD_ACCOUNT"].ToString());
                strSqlToUpdateBStyleDB.Append("',1,");
                strSqlToUpdateBStyleDB.Append(Convert.ToDecimal(this.TempDataTable.Rows[i]["RDPD_PAYAMT"]));
                strSqlToUpdateBStyleDB.Append(",'");
                strSqlToUpdateBStyleDB.Append(DateTime.Now);
                strSqlToUpdateBStyleDB.Append("','");
                strSqlToUpdateBStyleDB.Append(this.TempDataTable.Rows[i]["RDPD_DTCODE"].ToString());
                strSqlToUpdateBStyleDB.Append("')|");

                payAmount += Convert.ToDecimal(this.TempDataTable.Rows[i]["RDPD_PAYAMT"]);
                count++;
            }

            for (int i = 0; i < dlistCoupon.Items.Count; i++)
            {
                strSqlToUpdateBStyleDB.Append("update LIQUAN_CUSTOMER set frozen=0 where CouponCode='");
                strSqlToUpdateBStyleDB.Append(((Label)dlistCoupon.Items[i].FindControl("lblCouponCode")).Text);
                strSqlToUpdateBStyleDB.Append("' and CustomerCode='");
                strSqlToUpdateBStyleDB.Append(order.ORDER_CUSTOMERCODE);
                strSqlToUpdateBStyleDB.Append("'|");
                if (((CheckBox)dlistCoupon.Items[i].FindControl("chkCoupon")).Checked)
                {
                    strSqlToUpdateBStyleDB.Append("Insert into PayDetail([pd_id],[pd_detailid],[pd_paytype],[pd_payamt],[pd_paydate],[pd_dealid],[pd_dealdate],[pd_account],[PD_GET],[PD_GETAMT],[PD_GETDATE],[pd_note],[pd_dtcode])values('");
                    strSqlToUpdateBStyleDB.Append(this.Code);
                    strSqlToUpdateBStyleDB.Append("','");
                    strSqlToUpdateBStyleDB.Append(++count);
                    strSqlToUpdateBStyleDB.Append("','002',");
                    strSqlToUpdateBStyleDB.Append(((Label)dlistCoupon.Items[i].FindControl("lblCouponAmount")).Text);
                    strSqlToUpdateBStyleDB.Append(",'");
                    strSqlToUpdateBStyleDB.Append(DateTime.Now);
                    strSqlToUpdateBStyleDB.Append("','");
                    strSqlToUpdateBStyleDB.Append(((Label)dlistCoupon.Items[i].FindControl("lblCouponCode")).Text);
                    strSqlToUpdateBStyleDB.Append("','");
                    strSqlToUpdateBStyleDB.Append(DateTime.Now);
                    strSqlToUpdateBStyleDB.Append("','");
                    strSqlToUpdateBStyleDB.Append(order.ORDER_CUSTOMERCODE);
                    strSqlToUpdateBStyleDB.Append("',1,");
                    strSqlToUpdateBStyleDB.Append(((Label)dlistCoupon.Items[i].FindControl("lblCouponAmount")).Text);
                    strSqlToUpdateBStyleDB.Append(",'");
                    strSqlToUpdateBStyleDB.Append(DateTime.Now);
                    strSqlToUpdateBStyleDB.Append("','','001')|");

                    strSqlToUpdateBStyleDB.Append("update LIQUAN_CUSTOMER set frozen=1 where CouponCode='");
                    strSqlToUpdateBStyleDB.Append(((Label)dlistCoupon.Items[i].FindControl("lblCouponCode")).Text);
                    strSqlToUpdateBStyleDB.Append("' and CustomerCode='");
                    strSqlToUpdateBStyleDB.Append(order.ORDER_CUSTOMERCODE);
                    strSqlToUpdateBStyleDB.Append("'|");

                    strSqlToUpdateBStyleDB.Append("update czkzcdmx set state = 5 where CZKBH='");
                    strSqlToUpdateBStyleDB.Append(((Label)dlistCoupon.Items[i].FindControl("lblCouponCode")).Text);
                    strSqlToUpdateBStyleDB.Append("'|");

                    strSqlToUpdateErpDB.Append("update czkzcdmx set state = 5 where CZKBH='");
                    strSqlToUpdateErpDB.Append(((Label)dlistCoupon.Items[i].FindControl("lblCouponCode")).Text);
                    strSqlToUpdateErpDB.Append("'|");

                    couponPayAmount += Convert.ToDecimal(((Label)dlistCoupon.Items[i].FindControl("lblCouponAmount")).Text);
                }
            }

            if (payAmount + couponPayAmount < order.ORDER_AAMT)
            {
                throw new Exception("您输入的支付金额小于订单总金额，请重新输入！");
            }


            strSqlToUpdateBStyleDB.Append("update orderdoc set ORDER_CLEAR=1,ORDER_CLEARAMT=");
            strSqlToUpdateBStyleDB.Append(payAmount + couponPayAmount);
            strSqlToUpdateBStyleDB.Append(",ORDER_PAYAMT=");
            strSqlToUpdateBStyleDB.Append(payAmount + couponPayAmount);
            strSqlToUpdateBStyleDB.Append(",BYZD9='");
            strSqlToUpdateBStyleDB.Append(DateTime.Now);
            strSqlToUpdateBStyleDB.Append("' where ORDER_ID='");
            strSqlToUpdateBStyleDB.Append(this.Code);
            strSqlToUpdateBStyleDB.Append("'|");

            BLL.Promotion.BuildInitCouponSqlString(order.ORDER_AAMT, this.Code, order.ORDER_CUSTOMERCODE, strSqlToUpdateBStyleDB, strSqlToUpdateErpDB);

            if (couponPayAmount > 0)
            {
                strSqlToUpdateBStyleDB.Append("update orderdoc set ORDER_CLEAR=1,ORDER_CLEARAMT=");
                strSqlToUpdateBStyleDB.Append(payAmount + couponPayAmount);
                strSqlToUpdateBStyleDB.Append(",ORDER_PAYAMT=");
                strSqlToUpdateBStyleDB.Append(payAmount + couponPayAmount);
                strSqlToUpdateBStyleDB.Append(",BYZD9='");
                strSqlToUpdateBStyleDB.Append(DateTime.Now);
                strSqlToUpdateBStyleDB.Append("',Coupon=1,CouponMoney=");
                strSqlToUpdateBStyleDB.Append(couponPayAmount);
                strSqlToUpdateBStyleDB.Append(" where ORDER_ID='");
                strSqlToUpdateBStyleDB.Append(this.Code);
                strSqlToUpdateBStyleDB.Append("'|");

                BLL.Promotion.BuildInitCouponSqlString(payAmount, this.Code, order.ORDER_CUSTOMERCODE, strSqlToUpdateBStyleDB, strSqlToUpdateErpDB);
            }
            else if (couponPayAmount == 0)
            {
                strSqlToUpdateBStyleDB.Append("update orderdoc set ORDER_CLEAR=1,ORDER_CLEARAMT=");
                strSqlToUpdateBStyleDB.Append(payAmount + couponPayAmount);
                strSqlToUpdateBStyleDB.Append(",ORDER_PAYAMT=");
                strSqlToUpdateBStyleDB.Append(payAmount + couponPayAmount);
                strSqlToUpdateBStyleDB.Append(",BYZD9='");
                strSqlToUpdateBStyleDB.Append(DateTime.Now);
                strSqlToUpdateBStyleDB.Append("' where ORDER_ID='");
                strSqlToUpdateBStyleDB.Append(this.Code);
                strSqlToUpdateBStyleDB.Append("'|");

                BLL.Promotion.BuildInitCouponSqlString(order.ORDER_AAMT, this.Code, order.ORDER_CUSTOMERCODE, strSqlToUpdateBStyleDB, strSqlToUpdateErpDB);
            }

            Model.V_VIPSET userInfo = new BLL.V_VIPSET().GetModel(order.ORDER_CUSTOMERCODE);
            if (userInfo == null)
            {
                Share.Alert(Page, "系统内无此会员信息！"); return;
            }
            Model.V_VIP_ACCOUNT userAccount = new BLL.V_VIP_ACCOUNT().GetModel(userInfo.DM);

            if (userAccount == null)
            {
                strSqlToUpdateBStyleDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
                strSqlToUpdateBStyleDB.Append(userInfo.DM);
                strSqlToUpdateBStyleDB.Append("',0)|");

                strSqlToUpdateErpDB.Append("insert into v_vip_account(DM,DQJE_1) values('");
                strSqlToUpdateErpDB.Append(userInfo.DM);
                strSqlToUpdateErpDB.Append("',0)|");
            }

            if (payAmount > order.ORDER_AAMT)
            {
                string strUpdateVipAccountSqlString = new BLL.V_VIP_ACCOUNT().BuildUpdateVipAccountSqlString(payAmount - order.ORDER_AAMT, userInfo.DM);
                strSqlToUpdateBStyleDB.Append(strUpdateVipAccountSqlString);
                strSqlToUpdateErpDB.Append(strUpdateVipAccountSqlString);

                string strInsertBalanceManagementSqlString = new BLL.BALANCEADJUST().BuildInsertMainSqlString("008",order.ORDER_ID, operatorId, operatorId, order.ORDER_CUSTOMERCODE, payAmount - order.ORDER_AAMT);
                strSqlToUpdateBStyleDB.Append(strInsertBalanceManagementSqlString);
            }

            if (strSqlToUpdateErpDB.ToString() == "")
            {
                string stringSql = strSqlToUpdateBStyleDB.ToString();
                char[] charToTrim = new char[] { '|' };
                string[] sqlCommandArray = stringSql.TrimEnd(charToTrim).Split(charToTrim);
                result = new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray);
            }
            else
            {
                string stringSqlToUpdateBStyleDB = strSqlToUpdateBStyleDB.ToString();
                string stringSqlToUpdateErpDB = strSqlToUpdateErpDB.ToString();

                char[] charToTrim = new char[] { '|' };
                string[] strArray1 = stringSqlToUpdateBStyleDB.TrimEnd(charToTrim).Split(charToTrim);
                string[] strArray2 = stringSqlToUpdateErpDB.TrimEnd(charToTrim).Split(charToTrim);

                LX_Manage.ERP.Service webService = new LX_Manage.ERP.Service();
                result = webService.UpdateBalanceAndUsableDeliverAmountOfOneRecord(ConfigurationManager.AppSettings["WebServiceKey"].ToString(), strArray1, strArray2);
            }
            if (result)
            {
                //Response.Redirect("OrderDetail.aspx?code=" + this.Code);

                Response.Write("<script>alert('订单已结算成功！');location.href='OrderDetail.aspx?code=" + this.Code + "'</script>");
            }
            else
            {
                Share.Alert(Page, "订单结算失败，请重新操作！"); return;
            }
        }
        catch(Exception ex)
        {
            Share.Alert(this.Page,ex.Message);
        }
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {

    }

    protected void dlistPayDocPayDetail_ItemCommand(object source, DataListCommandEventArgs e)
    {
        try
        {
            if (e.CommandName.ToLower() == "del")
            {
                FillValueIntoDataTable(this.TempDataTable);

                BindDataListPayDocPayDetail(new BLL.PAYDOCPAYDETAIL().SubDataRowFromDataTable(this.TempDataTable, e.Item.ItemIndex));
            }
            //else if (e.CommandName.ToLower() == "upt")
            //{
            //    TextBox txtAmount;
            //    decimal payAmount = 0;
            //    for (int i = 0; i < dlistPayDocPayDetail.Items.Count; i++)
            //    {
            //        txtAmount = (TextBox)dlistPayDocPayDetail.Items[i].FindControl("txtPayAmount");
            //        payAmount += Convert.ToDecimal(txtAmount.Text.Trim() == "" ? "0" : txtAmount.Text.Trim());
            //    }

            //    txtReturnAmount.Text = String.Format("{0:0.00}", payAmount);
            //    txtReturnTotal.Text = String.Format("{0:0.00}", payAmount + Convert.ToDecimal(txtReverseAmount.Text));
            //}

        }
        catch (Exception ex)
        {
            Share.Alert(this.Page, ex.Message);
        }

    }

    protected void dlistPayDocPayDetail_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DropDownList dropDealType = (DropDownList)e.Item.FindControl("dropDealType");
            for (int i = 0; i < dropDealType.Items.Count; i++)
            {
                if (dropDealType.Items[i].Value == this.TempDataTable.Rows[e.Item.ItemIndex]["RDPD_DTCODE"].ToString())
                {
                    dropDealType.SelectedIndex = i;
                    break;
                }
            }

            DropDownList dropPayType = (DropDownList)e.Item.FindControl("dropPayType");

            if (dropPayType != null)
            {
                if (this.TempDataTable.Rows[e.Item.ItemIndex]["RDPD_DTCODE"].ToString() != "")
                {
                    BindDropPayType(this.TempDataTable.Rows[e.Item.ItemIndex]["RDPD_DTCODE"].ToString(), dropPayType);
                    for (int i = 0; i < dropPayType.Items.Count; i++)
                    {
                        if (dropPayType.Items[i].Value.Contains(this.TempDataTable.Rows[e.Item.ItemIndex]["RDPD_PAYTYPE"].ToString() + "|"))
                        {
                            dropPayType.SelectedIndex = i;
                            break;
                        }
                    }
                }
                else
                {
                    BindDropPayType(dropDealType.Items[0].Value, dropPayType);
                }


            }

            //TextBox txtPayAmount = (TextBox)e.Item.FindControl("txtPayAmount");
            //Button btnUpdate = (Button)e.Item.FindControl("btnUpdate");
            //txtPayAmount.Attributes.Add("onblur", btnUpdate.ClientID + ".click();");
        }
    }

    private void BindDataListPayDocPayDetail(DataTable tbl)
    {
        dlistPayDocPayDetail.DataSource = tbl;
        dlistPayDocPayDetail.DataBind();
    }

    protected void DataList2_DDLCHANGE_Click(object sender, EventArgs e)
    {
        DropDownList dropDealType = (DropDownList)sender;
        DropDownList dropPayType = (DropDownList)dropDealType.Parent.FindControl("dropPayType");
        BindDropPayType(dropDealType.SelectedValue, dropPayType);
    }

    private void BindDropPayType(string dealType, DropDownList drop)
    {
        DataSet dst = new BLL.PAYTYPE_DEALTYPE().P_DealType_GetPayTypeByCode(dealType);
        ListItem tempItem;
        drop.Items.Clear();
        for (int i = 0; i < dst.Tables[0].Rows.Count; i++)
        {
            tempItem = new ListItem();
            tempItem.Text = dst.Tables[0].Rows[i]["PT_NAME"].ToString();
            tempItem.Value = dst.Tables[0].Rows[i]["PT_CODE"].ToString() + "|" + dst.Tables[0].Rows[i]["PT_HAVEDEAL"].ToString();
            drop.Items.Add(tempItem);
        }

    }
    private void FillValueIntoDataTable(DataTable tbl)
    {
        DropDownList dropDealType;
        DropDownList dropPayType;
        TextBox txtPayAmount;
        TextBox txtPayDate;
        TextBox txtDealID;
        TextBox txtDealDate;
        TextBox txtAccount;
        TextBox txtNotes;

        for (int i = 0; i < dlistPayDocPayDetail.Items.Count; i++)
        {
            dropDealType = (DropDownList)dlistPayDocPayDetail.Items[i].FindControl("dropDealType");
            dropPayType = (DropDownList)dlistPayDocPayDetail.Items[i].FindControl("dropPayType");
            txtPayAmount = (TextBox)dlistPayDocPayDetail.Items[i].FindControl("txtPayAmount");
            txtPayDate = (TextBox)dlistPayDocPayDetail.Items[i].FindControl("txtPayDate");
            txtDealID = (TextBox)dlistPayDocPayDetail.Items[i].FindControl("txtDealID");
            txtDealDate = (TextBox)dlistPayDocPayDetail.Items[i].FindControl("txtDealDate");
            txtAccount = (TextBox)dlistPayDocPayDetail.Items[i].FindControl("txtAccount");
            txtNotes = (TextBox)dlistPayDocPayDetail.Items[i].FindControl("txtNotes");

            string[] selectValue = dropPayType.SelectedItem.Value.Split('|');
            if (selectValue[1] == "1" && txtDealID.Text.Trim() == "")
            {
                throw new Exception("您选择的支付方式必须输入交易号，请输入！");
            }

            tbl.Rows[i]["RDPD_DTCODE"] = dropDealType.SelectedValue;
            tbl.Rows[i]["RDPD_PAYTYPE"] = selectValue[0];
            tbl.Rows[i]["RDPD_PAYAMT"] = Convert.ToDecimal(txtPayAmount.Text.Trim());
            tbl.Rows[i]["RDPD_PAYDATE"] = Convert.ToDateTime(txtPayDate.Text.Trim());
            tbl.Rows[i]["RDPD_DEALID"] = txtDealID.Text.Trim();
            tbl.Rows[i]["RDPD_DEALDATE"] = Convert.ToDateTime(txtDealDate.Text.Trim());
            tbl.Rows[i]["RDPD_ACCOUNT"] = txtAccount.Text.Trim();
            tbl.Rows[i]["RDPD_NOTE"] = txtNotes.Text.Trim();
        }

    }

    protected void btnAddPayDocPayDetail_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.TempDataTable == null)
            {
                this.TempDataTable = new BLL.PAYDOCPAYDETAIL().CreateTempDataTable();
            }
            else
            {
                FillValueIntoDataTable(this.TempDataTable);
            }
            this.TempDataTable = new BLL.RETURNDOCPAYDETAIL().AddDataRowToDataTable(this.TempDataTable);
            BindDataListPayDocPayDetail(this.TempDataTable);
        }
        catch (Exception ex)
        {
            Share.Alert(this.Page, ex.Message);
        }
    }

    #region 礼券支付控件绑定及相关操作

    private void BindDataListCoupon()
    {
        DataSet dstUsableCouponOfCustomer = new BLL.LIQUAN_CUSTOMER().GetUsableCouponByCustomerCode(lblgmr.Text, this.Code);
        dlistCoupon.DataSource = dstUsableCouponOfCustomer;
        dlistCoupon.DataBind();
    }

    #endregion
}
